package com.lpb.spring.lpbspring.getway.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lpb.spring.lpbspring.getway.util.IdUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;


public class GeneralModel extends Defense implements Serializable, Comparable<GeneralModel> {

    public Long getId() {
        return null;
    }

    public void setId(Long id) {}

    public void setAid(String aid) {
        if (!IdUtils.isId(aid)) {
        }
        this.setId(IdUtils.getId(aid));
    }

    public void setBid(String bid) {
        if (!IdUtils.isId(bid)) {
        }
        this.setId(IdUtils.getId(bid));
    }

    public String getAid() {
        return IdUtils.getId(this.getId());
    }

    public String getBid() {
        return IdUtils.getInvariableId(this.getId());
    }

    public List<String> excludes() {
        return Arrays.asList("id", "deleted");
    }

    @Override
    public boolean equals(Object obj) {
        if (this.getClass() == obj.getClass()) {
            return this.getId().equals(((GeneralModel) obj).getId());
        }
        return super.equals(obj);
    }

    @Override
    public int compareTo(GeneralModel model) {
        if (this.getId() == null) {
            return 0;
        }
        return this.getId().intValue() - model.getId().intValue();
    }

    public JSONObject toJSON() {
        JSONObject json = (JSONObject) JSON.toJSON(this);
        this.excludes().forEach(json::remove);
        return json;
    }
}
